<template>
	<uni-search-bar @confirm="toSearch" placeholder="请输入搜索的公交地铁线路" v-model="searchKey" />
	<swiper style="height: 200px;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
		<swiper-item v-for="(item,index) in lunboList" :key="index">
			<view class="swiper-item">
				<image style="width: 100%;" :src="item.url" mode=""></image>
			</view>
		</swiper-item>

	</swiper>

	<view class="weather" style="height: 100rpx;border: 1px solid #ccc;margin: 5px; border-radius: 5px;display: flex;justify-content: space-between; padding: 10rpx;align-items: center;
		">
		<view class="icon" style="width: 100rpx;height: 100rpx; ">
			<image style="width: 100%;height: 100%;" :src="'/static/weather/icons/'+ weatherNow.icon +'.png'" mode="">
			</image>
		</view>
		<view class="text" style="font-size: 50rpx;margin-left: 10px;">
			{{weatherNow.temp}}°C
		</view>
		<view class="text" style="font-size: 34rpx;margin-left: 10rpx;">
			{{weatherNow.text}}
		</view>
		<view class="text" style=" margin-left: 10rpx;">
			{{weatherNow.windDir}} {{weatherNow.windScale}}级
		</view>
		<view>
			<view class="text" style="margin-left: 10rpx;">
				体感温度： {{weatherNow.feelsLike }}°C
			</view>
			<view class="text" style="margin-left: 10rpx;">
				湿度： {{weatherNow.humidity }}%
			</view>
		</view>
	</view>

	<uni-section title="旅游服务" sub-title="" type="line">
	</uni-section>
	<uni-grid :show-border="false" :column="4" @change="changeGrid">
		<uni-grid-item v-for="(item,index) in gridData" :index="index">
			<view class="grid-item-box" style="background-color: #fff;">
				<uni-icons :type="item.icon" :size="30" :color="item.color" />
				<text class="text">{{item.title}}</text>
			</view>
		</uni-grid-item>

	</uni-grid>
	<!-- 热映电影 -->
	<button type="default" @tap="tomovie">热映电影</button>

	<uni-section title="认识西安" sub-title="" type="line"></uni-section>
	<video style="width: 100%;" src="/static/video/xian.mp4" :autoplay="false" controls></video>



	<view class="title" style="text-align: center;"><b>西安历史名胜</b></view>
	<view class="history">
		<view class="item" v-for="(item,index) in jingdianList" :key="index">
			<view class="pic">
				<image :src="item.url" mode="scaleToFill"></image>
			</view>
			<view class="msg">{{item.name}}</view>
		</view>
	</view>

</template>

<script setup>
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config"

	import {
		userStore
	} from "../../store/userStore.js"
	const store = userStore()

	const searchKey = ref("")
	const jingdianList = ref([])

	function toSearch() {
		if (searchKey.value == "") {
			uni.showToast({
				title: "请输入查询的公交地图线路",
				icon: "none"
			})
		} else {
			window.location.href =
				`https://uri.amap.com/line?name=${searchKey.value}&city=029&callnative=1`
		}
	}

	onLoad(() => {
		getLunbo()
		getCurrentPos()
		getWeather()
		getjingdian()
		// getScene()
	})


	// 轮播的数据
	const lunboList = ref([])
	// 获取轮播数据
	async function getLunbo() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/Lunbo")
		if (res.statusCode == 200) {
			lunboList.value = res.data.results
		} else {
			uni.showToast({
				title: '数据获取错误',
				icon: 'none'
			})
		}
		console.log(lunboList.value)
	}
	// 当前经纬度
	function getCurrentPos() {
		uni.getLocation({
			success: function(res) {
				console.log('当前位置的经度:' + res.longitude);
				console.log('当前位置的维度:' + res.latitude);
				store.setPos(res.longitude, res.latitude)
			}

		})
	}
	// 实时天气获取
	let weatherNow = ref({})
	async function getWeather() {
		let res = await uni.$get(CONFIG.hefeng_now, {
			key: CONFIG.hefeng_key,
			location: CONFIG.hefeng_location
		})
		if (res.data.code == 200) {
			weatherNow.value = res.data.now
			console.log(res.now)
		}
	}

	//调用默认浏览器打开
	function toweather() {
		window.location.href =
			`//uri.amap.com/navigation?from=118.115948,24.470662,我的位置&to=118.092515,24.436698终点&mode=car&policy=1&src=com.mzwu.www&callnative=1`

	}

	let gridData = [{
			title: '热映电影',
			color: '#CCCC99'
		},
		{
			title: '天气预报',
			color: '#FF99CC'
		},
		{
			title: '景点',
			color: '#003333'
		},
		{
			title: '我在哪里',
			url: "/pages/transport/transport",
			color: '#336699'
		},
	]

	function changeGrid(e) {

		let url = gridData[e.detail.index].url
		if (url) {

			uni.navigateTo({
				url
			})
			console.log(e.detail.index)
		}
	}

	// 景点
	async function getjingdian() {
		let res = await uni.$get(CONFIG.leanCloud_url + "/1.1/classes/jingdian")
		console.log(res)
		if (res.statusCode == 200) {
			jingdianList.value = res.data.results
		}
		console.log(jingdianList.value)
	}

	// 电影
	function tomovie() {
		uni.navigateTo({
			url: "/pages/hotMovie/hotMovie"
		})
	}
</script>

<style lang="scss" scoped>
	body{
		background-color: snow;
	}
	.seen {
		width: 730rpx;
		border: 1px solid #eee;

		margin: 10rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;

		.item {
			width: 320rpx;
			padding: 10px;
			height: 200rpx;
			border: 1px solid #eee;
			box-shadow: 3px 3px 3px #eee;

			border-radius: 5px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				font-size: 28rpx;
				font-weight: bold;
				text-align: center;
			}

			.pic {
				width: 100%;
				height: 150rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.grid-item-box {
		width: 100%;
	}

	.history {
		display: flex;
		justify-content: space-evenly;
		flex-wrap: wrap;
	}

	.history>.item {
		margin-top: 10rpx;
		width: 350rpx;
		border: 1px solid #ccc;
		border-radius: 5rpx;
		display: flex;

		flex-direction: column;
		align-items: center;
		box-shadow: 3px 3px 3px #eee;
	}

	.history>.item>.pic {
		width: 330rpx;
		height: 200rpx;
		margin-top: 10rpx;
	}

	.history>.item>.pic>image {
		width: 100%;
		height: 100%;
	}
</style>